package com.wuhan.template.module.home.activity;

import android.support.v4.app.FragmentManager;
import android.widget.RadioGroup;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseActivity;
import com.wuhan.template.base.BaseFragment;
import com.wuhan.template.module.find.FindFragment;
import com.wuhan.template.module.home.fragment.MyFragment;
import com.wuhan.template.module.home.fragment.ZiXunFragment;
import com.wuhan.template.module.wode.fragment.WoDeFragment;
import com.wuhan.template.module.zixun.fragment.ZixunFragment;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import greendao.DetailTableDao;

public class MainActivity extends BaseActivity {
    SlidingMenu menu = null;
    private FragmentManager manager;
    private DetailTableDao dao;

    @BindView(R.id.home_navigation)
    protected RadioGroup navigationGroup;

    private MyFragment myFragment;
    private ZiXunFragment ziXunFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    /**
     * 初始化视图
     */
    @Override
    protected void initViews() {

        manager = getSupportFragmentManager();

        //
        Map<String, String> params = new HashMap<>();
        params.put("tag", "1");

        Map<String, String> params2 = new HashMap<>();
        params2.put("tag2", "2");

        //
        myFragment = BaseFragment.newInstance(MyFragment.class, params);
        ziXunFragment = BaseFragment.newInstance(ZiXunFragment.class, params2);

        // 默认先显示首页
        manager.beginTransaction().replace(R.id.fl_main, myFragment).commit();


        navigationGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.home_shouye:
                        manager.beginTransaction().replace(R.id.fl_main, myFragment).commit();
                        break;
                    case R.id.home_zixun:
                        manager.beginTransaction().replace(R.id.fl_main, ZiXunFragment.newInstance(ZixunFragment.class,null)).commit();
                        break;

                    case R.id.home_faxian:
                        manager.beginTransaction().replace(R.id.fl_main, FindFragment.newInstance(FindFragment.class,null)).commit();
                        break;

                    case R.id.home_wode:
                        manager.beginTransaction().replace(R.id.fl_main, BaseFragment.newInstance(WoDeFragment.class,null)).commit();
                        break;
                }
            }
        });

       /* dao = getDaoSession().getLoreDetailTableDao();

        // 添加
        LoreDetailTable loreDetail = new LoreDetailTable();
        loreDetail.setTitle("标题内容");
        loreDetail.setImageUrl("111111111");
        dao.insert(loreDetail);

        // 查询
        Query<LoreDetailTable> query = dao.queryRawCreate("_id = ?",1);
        List<LoreDetailTable> list = query.list();


        // 使用QueryBuilder查询
        QueryBuilder<LoreDetailTable> qb = dao.queryBuilder();
        qb.where(LoreDetailTableDao.Properties.Id.eq(1));
        long count = qb.buildCount().count();

        // 使用链式法
        list = dao.queryBuilder()
                .where(LoreDetailTableDao.Properties.Title.eq("标题内容"))
                .orderAsc(LoreDetailTableDao.Properties.Id)
                .list();

        // 查找某一个对象
        LoreDetailTable loreDetailTable =
                dao.queryBuilder()
                        .where(LoreDetailTableDao.Properties.Id.eq(1))
                        .unique();

        // 删除
        //dao.deleteByKey(1l);
        dao.delete(loreDetailTable);

        // 修改
        loreDetailTable.setTitle("修改标题");
        dao.update(loreDetailTable);
*/
    }

}
